// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
parcelRequire = (function (modules, cache, entry, globalName) {
  // Save the require from previous bundle to this closure if any
  var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
  var nodeRequire = typeof require === 'function' && require;

  function newRequire(name, jumped) {
    if (!cache[name]) {
      if (!modules[name]) {
        // if we cannot find the module within our internal map or
        // cache jump to the current global require ie. the last bundle
        // that was added to the page.
        var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
        if (!jumped && currentRequire) {
          return currentRequire(name, true);
        }

        // If there are other bundles on this page the require from the
        // previous one is saved to 'previousRequire'. Repeat this as
        // many times as there are bundles until the module is found or
        // we exhaust the require chain.
        if (previousRequire) {
          return previousRequire(name, true);
        }

        // Try the node require function if it exists.
        if (nodeRequire && typeof name === 'string') {
          return nodeRequire(name);
        }

        var err = new Error('Cannot find module \'' + name + '\'');
        err.code = 'MODULE_NOT_FOUND';
        throw err;
      }

      localRequire.resolve = resolve;
      localRequire.cache = {};

      var module = cache[name] = new newRequire.Module(name);

      modules[name][0].call(module.exports, localRequire, module, module.exports, this);
    }

    return cache[name].exports;

    function localRequire(x){
      return newRequire(localRequire.resolve(x));
    }

    function resolve(x){
      return modules[name][1][x] || x;
    }
  }

  function Module(moduleName) {
    this.id = moduleName;
    this.bundle = newRequire;
    this.exports = {};
  }

  newRequire.isParcelRequire = true;
  newRequire.Module = Module;
  newRequire.modules = modules;
  newRequire.cache = cache;
  newRequire.parent = previousRequire;
  newRequire.register = function (id, exports) {
    modules[id] = [function (require, module) {
      module.exports = exports;
    }, {}];
  };

  var error;
  for (var i = 0; i < entry.length; i++) {
    try {
      newRequire(entry[i]);
    } catch (e) {
      // Save first error but execute all entries
      if (!error) {
        error = e;
      }
    }
  }

  if (entry.length) {
    // Expose entry point to Node, AMD or browser globals
    // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
    var mainExports = newRequire(entry[entry.length - 1]);

    // CommonJS
    if (typeof exports === "object" && typeof module !== "undefined") {
      module.exports = mainExports;

    // RequireJS
    } else if (typeof define === "function" && define.amd) {
     define(function () {
       return mainExports;
     });

    // <script>
    } else if (globalName) {
      this[globalName] = mainExports;
    }
  }

  // Override the current require with this new one
  parcelRequire = newRequire;

  if (error) {
    // throw error from earlier, _after updating parcelRequire_
    throw error;
  }

  return newRequire;
})({"src/model/Controller.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Contoller = void 0;

var Contoller =
/** @class */
function () {
  function Contoller() {}

  return Contoller;
}();

exports.Contoller = Contoller;
},{}],"src/model/Card.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Card = void 0;

var _tslib = require("tslib");

var _Controller = require("./Controller");

var Card =
/** @class */
function (_super) {
  (0, _tslib.__extends)(Card, _super);

  function Card(option) {
    var _this = _super.call(this) || this;

    _this.option = option;
    return _this;
  }

  Card.prototype.type = function () {
    return "SGS.Model.Card";
  };

  Card.prototype.effect = function (callback) {
    if (this.option.effect) {
      return this.option.effect();
    }

    if (callback) {
      callback();
    }
  };

  return Card;
}(_Controller.Contoller);

exports.Card = Card;
},{"./Controller":"src/model/Controller.ts"}],"src/core/event/index.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EVENT = exports.events = void 0;

var _events = _interopRequireDefault(require("events"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var events = new _events.default.EventEmitter();
exports.events = events;
var SGS_EVENT = {};
var EVENT;
exports.EVENT = EVENT;

(function (EVENT) {
  EVENT.s = 2;
})(EVENT || (exports.EVENT = EVENT = {}));
},{}],"src/core/utils/array.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.shuffle = shuffle;
exports.repeat = repeat;

function shuffle(arr) {
  var _a;

  for (var i = 0; i < arr.length; i++) {
    var randomIndex = Math.round(Math.random() * (arr.length - 1 - i)) + i;
    _a = [arr[randomIndex], arr[i]], arr[i] = _a[0], arr[randomIndex] = _a[1];
  }

  return arr;
}

function repeat(arr, times) {
  var arrCopy = arr.slice();

  for (var i = 0; i < times; i++) {
    arr = arr.concat(arrCopy);
  }

  return arr;
}
},{}],"src/core/utils/setting.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.provideSuitableCamps = provideSuitableCamps;
var campDefine = [{
  playerNum: 5,
  name: "五人局",
  value: ["ZG", "FZ", "FZ", "ZC", "NJ"]
}];

function provideSuitableCamps(playerNum) {
  var result = [];

  for (var i = 0; i < campDefine.length; i++) {
    if (playerNum === campDefine[i].playerNum) {
      result = campDefine[i].value;
      break;
    }
  }

  return result;
}
},{}],"src/core/utils/index.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "repeat", {
  enumerable: true,
  get: function () {
    return _array.repeat;
  }
});
Object.defineProperty(exports, "shuffle", {
  enumerable: true,
  get: function () {
    return _array.shuffle;
  }
});
Object.defineProperty(exports, "provideSuitableCamps", {
  enumerable: true,
  get: function () {
    return _setting.provideSuitableCamps;
  }
});
exports.default = void 0;

var _array = require("./array");

var _setting = require("./setting");

var SGS_Util = {
  repeat: _array.repeat,
  shuffle: _array.shuffle,
  provideSuitableCamps: _setting.provideSuitableCamps
};
var _default = SGS_Util;
exports.default = _default;
},{"./array":"src/core/utils/array.ts","./setting":"src/core/utils/setting.ts"}],"src/module/basic/card/index.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.cards = void 0;

var _Card = require("./../../../model/Card");

var _event = require("/src/core/event");

var _utils = _interopRequireDefault(require("/src/core/utils"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var cardsData = [{
  id: "SGS.MODULE.BASIC.CARD.SHA",
  name: "杀",
  type: "BASIC",
  color: "HEART",
  point: "1",
  effect: function () {
    _event.events.emit("SGS.CARD_EFFECT.SHA");
  }
}, {
  id: "SGS.MODULE.BASIC.CARD.SHAN",
  name: "闪",
  type: "BASIC",
  color: "HEART",
  point: "2",
  effect: function () {
    _event.events.emit("SGS.CARD_EFFECT.SHAN");
  }
}, {
  id: "SGS.MODULE.BASIC.CARD.TAO",
  name: "桃",
  type: "BASIC",
  color: "HEART",
  point: "2",
  effect: function () {
    _event.events.emit("SGS.CARD_EFFECT.TAO");
  }
}];

var cards = _utils.default.repeat(cardsData, 20).map(function (v) {
  return new _Card.Card(v);
});

exports.cards = cards;
},{"./../../../model/Card":"src/model/Card.ts","/src/core/event":"src/core/event/index.ts","/src/core/utils":"src/core/utils/index.ts"}],"src/model/Hero.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Hero = void 0;

var _tslib = require("tslib");

var _Controller = require("./Controller");

var Hero =
/** @class */
function (_super) {
  (0, _tslib.__extends)(Hero, _super);

  function Hero(option) {
    var _this = _super.call(this) || this;

    _this.option = option;
    return _this;
  }

  Hero.prototype.type = function () {
    return "SGS.Model.Hero";
  };

  Hero.prototype.getCurrentHP = function () {
    return this.option.HP;
  };

  Hero.prototype.setCurrentHP = function (HP) {
    this.option.HP = HP;
  };

  return Hero;
}(_Controller.Contoller);

exports.Hero = Hero;
},{"./Controller":"src/model/Controller.ts"}],"src/module/basic/hero/index.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.heroes = void 0;

var _Hero = require("/src/model/Hero");

var heroesData = [{
  name: "刘备",
  id: "SGS.MODULE.BASIC.HERO_LIUBEI",
  power: "SHU",
  HP: 4,
  skill: {}
}];
var heroes = heroesData.map(function (v) {
  return new _Hero.Hero(v);
});
exports.heroes = heroes;
},{"/src/model/Hero":"src/model/Hero.ts"}],"src/model/Module.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ModelModule = void 0;

var ModelModule =
/** @class */
function () {
  function ModelModule(moduleOptions) {
    this.moduleOptions = moduleOptions;
  }

  ModelModule.prototype.privide = function () {
    return {
      card: this.moduleOptions.cards,
      hero: this.moduleOptions.heroes,
      moduleName: this.moduleOptions.moduleName
    };
  };

  return ModelModule;
}();

exports.ModelModule = ModelModule;
},{}],"src/module/basic/index.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SGS_MODULE_BASIC = void 0;

var _card = require("./card");

var _hero = require("./hero");

var _Module = require("/src/model/Module");

var SGS_MODULE_BASIC = new _Module.ModelModule({
  cards: _card.cards,
  heroes: _hero.heroes,
  moduleName: 'SGS_MODULE_BASIC'
});
exports.SGS_MODULE_BASIC = SGS_MODULE_BASIC;
},{"./card":"src/module/basic/card/index.ts","./hero":"src/module/basic/hero/index.ts","/src/model/Module":"src/model/Module.ts"}],"src/model/Player.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Player = void 0;

var _tslib = require("tslib");

var _Controller = require("./Controller");

var Player =
/** @class */
function (_super) {
  (0, _tslib.__extends)(Player, _super);

  function Player(option) {
    var _this = _super.call(this) || this;

    _this.option = option;
    _this.card = [];
    return _this;
  }

  Player.prototype.type = function () {
    return "SGS.Model.Player";
  };

  Player.prototype.injectHero = function (hero) {
    if (this.hero === undefined) {
      this.hero = hero;
    } else {
      throw Error("Hero is already defined.");
    }
  };

  Player.prototype.includeCard = function (type, card) {
    switch (type) {
      case "init":
        this.card = card;
        break;

      case "add":
        this.card = (0, _tslib.__spreadArrays)(this.card, card);
        break;

      default:
        break;
    }
  };

  return Player;
}(_Controller.Contoller);

exports.Player = Player;
},{"./Controller":"src/model/Controller.ts"}],"src/core/game/index.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Game = void 0;

var _Player = require("./../../model/Player");

var _utils = _interopRequireDefault(require("../utils"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var Game =
/** @class */
function () {
  function Game(gameOptions) {
    this.gameOptions = gameOptions;
    this.modules = [];
  }

  Game.prototype.loadSource = function (modules) {
    var _this = this;

    modules.forEach(function (v, k) {
      return _this.modules[k] = v;
    });

    if (this.cards === undefined) {
      this.initCard();
    } else {
      console.log("WARN: 卡牌类已经有定义 @(core/game/index.ts/Game/initCard)");
    }

    if (this.players === undefined) {
      this.initPlayer({
        num: this.gameOptions.player.total
      });
    } else {
      console.log("WARN: 玩家类已经有定义 @(core/game/index.ts/Game/initPlayer)");
    }
  };

  Game.prototype.initCard = function () {
    var INIT_CARD = [];
    this.modules.forEach(function (module) {
      INIT_CARD = INIT_CARD.concat(module.privide().card);
    });
    this.cards = _utils.default.shuffle(INIT_CARD);
    console.log("cards: ", this.cards);
  };

  Game.prototype.initPlayer = function (options) {
    var SHUFFLE_CAMP = _utils.default.shuffle(_utils.default.provideSuitableCamps(options.num));

    var INIT_PLAYER = [];

    for (var i = 0; i < options.num; i++) {
      INIT_PLAYER.push(new _Player.Player({
        index: i,
        camp: SHUFFLE_CAMP[i]
      }));
    }

    this.players = INIT_PLAYER; // console.log("players: ", this.players);
  };

  return Game;
}();

exports.Game = Game;
},{"./../../model/Player":"src/model/Player.ts","../utils":"src/core/utils/index.ts"}],"src/app.ts":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = AppRun;

var _basic = require("/src/module/basic");

var _index = require("./core/game/index");

var game = new _index.Game({
  player: {
    total: 5
  }
});

function AppRun() {
  game.loadSource([_basic.SGS_MODULE_BASIC]);
}
},{"/src/module/basic":"src/module/basic/index.ts","./core/game/index":"src/core/game/index.ts"}],"main.ts":[function(require,module,exports) {
"use strict";

var _app = _interopRequireDefault(require("./src/app"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(0, _app.default)();
},{"./src/app":"src/app.ts"}]},{},["main.ts"], null)